package com.lagou.edu.config;

import com.lagou.edu.utils.IpUtils;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

/**
 * @Description TODO
 * @Classname RequestRateLimiterConfig
 * @Date 2021/5/30 23:53
 * @Author ch'ien
 */

@Configuration
public class RequestRateLimiterConfig {

    @Bean
    KeyResolver ipKeyResolver() {
        //按IP来限流
        return exchange -> Mono.just(IpUtils.getIpAddr(exchange.getRequest()));
    }
}
